<?php
/**
* @file $Id: DocumentTemplates.php 520 2007-05-14 07:29:44Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

DrawHeader(ProgramTitle());

if($_FILES['values'])
{
	foreach($_FILES['values']['tmp_name'] as $id=>$cells)
	{
		foreach($cells as $cell=>$file)
		{
			$file = $file['file'];
			if(function_exists(exif_imagetype))
			{
				if(exif_imagetype($file)==IMAGETYPE_GIF)
					$extension = '.gif';
				elseif(exif_imagetype($file)==IMAGETYPE_JPEG)
					$extension = '.jpg';
				else
				{
					$error = _('You can only upload images that are in GIF or JPEG format.');
					continue;
				}
			}
			else // fix
				$extension = substr($file,strpos($file,'.'));

			if($_REQUEST['values'][$id][$cell]['file_title'])
				$title = str_replace("'","''",str_replace(' ','_',str_replace('\\','',str_replace('/','',str_replace('.','',$_REQUEST['values'][$id][$cell]['file_title']))))).$extension;
			else
			{
				$error = _('You must enter a title for your image.');
				continue;
			}

			if(!move_uploaded_file($file,$uploaded_assets_dir.$title))
				$error = _("The image you tried to upload could not be saved.  This is likely a system-configuration issue.  See a system administrator.");
			else
			{
				$_REQUEST['values'][$id][$cell]['text'] = '<IMG SRC="'.$uploaded_assets_url.'/'.$title.'">';
				chmod($uploaded_assets_dir.'/'.$title,0666);
			}
		}
	}
}

if($_REQUEST['values'] && $_POST['values'] && AllowEdit())
{
	$current_RET = DBGet(DBQuery("SELECT ID,LEFT_CELL,MIDDLE_CELL,RIGHT_CELL FROM HEADER_ROWS WHERE TEMPLATE_ID='$_REQUEST[template_id]'"),array(),array('ID'));

	foreach($_REQUEST['values'] as $id=>$columns)
	{
		if($id!='headernew' && $id!='footernew')
		{
			$sql = "UPDATE HEADER_ROWS SET ";
							
			foreach($columns as $column=>$value)
			{
				if($column!='SORT_ORDER' && $column!='STYLE' && $column!='BORDER')
				{
					$current = $current_RET[$id][1][$column];
					$text = substr($current,0,strrpos($current,'~'));
					$field = substr($current,strrpos($current,'~')+1);
					if(!array_key_exists('field',$value))
						$value['field'] = $field;
					if(!array_key_exists('text',$value))
						$value['text'] = str_replace("'","\'",$text);

					$sql .= $column."='".str_replace("\'","''",$value['text'].'~'.$value['field'])."',";
				}
				else
					$sql .= $column."='".str_replace("\'","''",$value)."',";
			}
			$sql = substr($sql,0,-1) . " WHERE ID='$id'";
			DBQuery($sql);
		}
		else
		{
			$sql = "INSERT INTO HEADER_ROWS ";

			$type = substr($id,0,6);
			$fields = 'ID,TYPE,TEMPLATE_ID,';
			$values = db_seq_nextval('HEADER_ROWS_SEQ').",'".$type."','$_REQUEST[template_id]',";

			$go = 0;
			foreach($columns as $column=>$value)
			{
				if($value['text'] || $value['field'])
				{
					$fields .= $column.',';
					if($column!='SORT_ORDER' && $column!='STYLE' && $column!='BORDER')
						$values .= "'".str_replace("\'","''",$value['text'].'~'.$value['field'])."',";
					else
						$values .= "'".str_replace("\'","''",$value)."',";
					$go = true;
				}
			}
			$sql .= '(' . substr($fields,0,-1) . ') values(' . substr($values,0,-1) . ')';
			
			if($go)
				DBQuery($sql);
		}
	}
	unset($_REQUEST['values']);
	unset($_SESSION['_REQUEST_vars']['values']);
}

if($_REQUEST['modfunc']=='remove' && AllowEdit())
{
	if($_REQUEST['remove_template']=='true')
	{
		if(DeletePrompt(_('template')))
		{
			DBQuery("DELETE FROM HEADER_TEMPLATES WHERE ID='$_REQUEST[template_id]'");
			DBQuery("DELETE FROM HEADER_ROWS WHERE TEMPLATE_ID='$_REQUEST[template_id]'");
			unset($_REQUEST['modfunc']);
			unset($_REQUEST['template_id']);
			unset($_REQUEST['remove_template']);
			unset($_REQUEST['delete_ok']);
		}
	}
	elseif(DeletePrompt(_('row')))
	{
		DBQuery("DELETE FROM HEADER_ROWS WHERE ID='$_REQUEST[id]'");
		unset($_REQUEST['modfunc']);
	}
}

if($_REQUEST['template_id']=='new' && $_REQUEST['title'])
{
	$id = DBGet(DBQuery("SELECT ".db_seq_nextval('ATTENDANCE_CODE_CATEGORIES_SEQ').' AS ID'.FROM_DUAL));
	$id = $id[1]['ID'];
	DBQuery("INSERT INTO HEADER_TEMPLATES (ID,TITLE) values('".$id."','".str_replace("\'","''",$_REQUEST['title'])."')");
	DBQuery("INSERT INTO HEADER_ROWS (ID,TEMPLATE_ID,TYPE) values(".db_seq_nextval('HEADER_ROWS_SEQ').",'".$id."','pageh')");
	DBQuery("INSERT INTO HEADER_ROWS (ID,TEMPLATE_ID,TYPE) values(".db_seq_nextval('HEADER_ROWS_SEQ').",'".$id."','pagef')");
	$_REQUEST['template_id'] = $id;
	unset($_REQUEST['title']);
}


if($_REQUEST['modfunc']!='remove')
{
	$templates_RET = DBGet(DBQuery("SELECT ID,TITLE FROM HEADER_TEMPLATES ORDER BY SORT_ORDER"));
	
	//$header = '<TABLE border=0 cellpadding=0 cellspacing=0 height=14><TR>';
	$tmp_REQUEST = $_REQUEST;
	unset($tmp_REQUEST['template_id']);
	
	$tmp_PHP_SELF = PreparePHP_SELF($tmp_REQUEST);
	
	foreach($templates_RET as $template)
	{
		if($_REQUEST['template_id']!==$template['ID'])
		{
			$tabcolor = 'DFDFDF';
			$textcolor = '666666';
		}
		else
		{
			$tabcolor = Preferences('HIGHLIGHT');
			$textcolor = 'FFFFFF';
		}
	
		$header .= '<TD width=10></TD><TD>'.DrawTab($template['TITLE'],$tmp_PHP_SELF.'&amp;template_id='.$template['ID'],$tabcolor,$textcolor,'_circle',array('tabcolor'=>Preferences('HIGHLIGHT'),'textcolor'=>'FFFFFF')).'</TD>';
	}
	if($_REQUEST['template_id']!=='new')
	{
		$tabcolor = 'DFDFDF';
		$textcolor = '666666';
	}
	else
	{
		$tabcolor = Preferences('HIGHLIGHT');
		$textcolor = 'FFFFFF';
	}
	
	$header .= '<TD width=10></TD><TD>'.DrawTab(($_REQUEST['template_id']=='new'?button('white_add'):button('add'))._('Add a Template'),$tmp_PHP_SELF.'&amp;template_id=new',$tabcolor,$textcolor,'_circle',array('tabcolor'=>Preferences('HIGHLIGHT'),'textcolor'=>'FFFFFF')).'</TD>';
	//$header .= '</TR></TABLE>';
	
	echo TabsHeader($header);
}

if($_REQUEST['template_id']=='new' && !$_REQUEST['title'])
{	
	echo '<BR>';
	PopTable('header',_('Add a Template'));
	echo "<FORM action=Modules.php?modname=$_REQUEST[modname]&template_id=new method=POST>";
	echo _('Title').' <INPUT type=text name=title>';
	echo '<INPUT type=submit value='._('Submit').'>';
	echo '</FORM>';
	PopTable('footer');
}

if($_REQUEST['template_id'] && $_REQUEST['template_id']!='new' && $_REQUEST['modfunc']!='remove')
{
?>
<script language=javascript>
function getXPos(id)
{
	var x = 0;
	if(document.layers)
		x = document.layers[id].pageX;
	else if(document.all || document.getElementById) 
	{
		var cell = document.all ? document.all[id] : document.getElementById(id);
		while(cell)
		{
			x += cell.offsetLeft;
			cell = cell.offsetParent;
		}
	}
	return x;
}

function getYPos(id)
{
	var y = 0;
	if(document.layers)
		y = document.layers[id].pageY;
	else if(document.all || document.getElementById) 
	{
		var cell = document.all ? document.all[id] : document.getElementById(id);
		while(cell)
		{
			y += cell.offsetTop;
			cell = cell.offsetParent;
		}
	}
	return y;
}
</script>
<?php
	echo "<FORM enctype='multipart/form-data' action=Modules.php?modname=$_REQUEST[modname]&template_id=$_REQUEST[template_id] method=POST>";
	if($error)
		$error = '<font color=red><b>'._('Error').': </b></font>'.$error;
	DrawHeader($error,"<TABLE><TR><TD><IMG SRC=assets/help.gif align=bottom onclick=\"parent.help.expandFrame();parent.help.location.href='Bottom.php?modname=true&expanded=true';\"></TD><TD><IMG SRC=assets/pixel_trans.gif width=10 height=1><INPUT type=button value="._('Delete')." onclick='document.location.href=\"Modules.php?modname=".$_REQUEST['modname']."&modfunc=remove&remove_template=true&template_id=".$_REQUEST['template_id']."\"'><IMG SRC=assets/pixel_trans.gif width=10 height=1>".SubmitButton(_('Save')).'</TD></TR></TABLE>');

	$page_header_RET = DBGet(DBQuery("SELECT ID,LEFT_CELL,MIDDLE_CELL,RIGHT_CELL,TYPE FROM HEADER_ROWS WHERE TEMPLATE_ID='".$_REQUEST['template_id']."' AND TYPE='pageh'"),array('LEFT_CELL'=>'_makeCell','MIDDLE_CELL'=>'_makeCell','RIGHT_CELL'=>'_makeCell'));
	$page_header_RET = $page_header_RET[1];
	echo '<BR>';
	echo '<TABLE cellpadding=0 cellspacing=0><TR><TD rowspan=3><IMG SRC=assets/page_header.gif></TD><TD width=10 height=10><IMG SRC=assets/bracket_top.gif></TD>';
	echo '<TD rowspan=3 width=100%>';
	DrawHeader('<TABLE style="display:inline;" width=100%><TR><TD>'.$page_header_RET['LEFT_CELL'].'</TD><TD>'.$page_header_RET['MIDDLE_CELL'].'</TD><TD>'.$page_header_RET['RIGHT_CELL'].'</TD></TR></TABLE>');
	echo '</TD></TR>';
	echo '<TR><TD width=10 background=assets/bracket_middle.gif height=59> &nbsp;</TD></TR><TR><TD width=10 height=10 valign=bottom><IMG SRC=assets/bracket_bottom.gif></TD></TR></TABLE>';


	$functions = array('SORT_ORDER'=>'_makeSortOrder','STYLE'=>'_makeStyle','LEFT_CELL'=>'_makeCell','MIDDLE_CELL'=>'_makeCell','RIGHT_CELL'=>'_makeCell');
	$functions = array('SORT_ORDER'=>'_makeSortOrder','STYLE'=>'_makeStyle','LEFT_CELL'=>'_makeCell','MIDDLE_CELL'=>'_makeCell','RIGHT_CELL'=>'_makeCell');
	$header_rows_RET = DBGet(DBQuery("SELECT ID,SORT_ORDER,LEFT_CELL,MIDDLE_CELL,RIGHT_CELL,STYLE,BORDER FROM HEADER_ROWS WHERE TEMPLATE_ID='".$_REQUEST['template_id']."' AND TYPE='header' ORDER BY SORT_ORDER"),$functions);
	
	$columns = array('SORT_ORDER'=>_('Sort Order'),'STYLE'=>_('Style'),'LEFT_CELL'=>_('Left Cell'),'MIDDLE_CELL'=>_('Middle Cell'),'RIGHT_CELL'=>_('Right Cell'));
	$link['remove']['link'] = "Modules.php?modname=$_REQUEST[modname]&modfunc=remove&template_id=$_REQUEST[template_id]";
	$link['remove']['variables'] = array('id'=>'ID');
	$link['add']['html'] = array('SORT_ORDER'=>_makeSortOrder('','SORT_ORDER','header'),'STYLE'=>_makeStyle('','STYLE','header'),'LEFT_CELL'=>_makeCell('','LEFT_CELL','header'),'MIDDLE_CELL'=>_makeCell('','MIDDLE_CELL','header'),'RIGHT_CELL'=>_makeCell('','RIGHT_CELL','header'));

	echo '<BR>';
	echo '<TABLE cellpadding=0 cellspacing=0><TR><TD rowspan=3><IMG SRC=assets/document_header.gif></TD><TD width=10 height=10><IMG SRC=assets/bracket_top.gif></TD>';
	echo '<TD rowspan=3 width=100%>';
	ListOutput($header_rows_RET,$columns,_('document header row'),_('document header rows'),$link);
	echo '</TD></TR>';
	echo '<TR><TD width=10 background=assets/bracket_middle.gif> &nbsp;</TD></TR><TR><TD width=10 height=10 valign=bottom><IMG SRC=assets/bracket_bottom.gif></TD></TR></TABLE>';

	echo '<BR>';
	echo '<TABLE width=100% background=assets/bottom.gif><TR><TD> &nbsp; </TD></TR></TABLE>';

	$footer_rows_RET = DBGet(DBQuery("SELECT ID,SORT_ORDER,LEFT_CELL,MIDDLE_CELL,RIGHT_CELL,STYLE,BORDER FROM HEADER_ROWS WHERE TEMPLATE_ID='".$_REQUEST['template_id']."' AND TYPE='footer' ORDER BY SORT_ORDER"),$functions);
	$link['add']['html'] = array('SORT_ORDER'=>_makeSortOrder('','SORT_ORDER','footer'),'STYLE'=>_makeStyle('','STYLE','footer'),'LEFT_CELL'=>_makeCell('','LEFT_CELL','footer'),'MIDDLE_CELL'=>_makeCell('','MIDDLE_CELL','footer'),'RIGHT_CELL'=>_makeCell('','RIGHT_CELL','footer'));

	echo '<BR>';
	echo '<TABLE cellpadding=0 cellspacing=0><TR><TD rowspan=3><IMG SRC=assets/document_footer.gif></TD><TD width=10 height=10><IMG SRC=assets/bracket_top.gif></TD>';
	echo '<TD rowspan=3 width=100%>';
	ListOutput($footer_rows_RET,$columns,_('document footer row'),_('document footer rows'),$link);
	echo '</TD></TR>';
	echo '<TR><TD width=10 background=assets/bracket_middle.gif> &nbsp;</TD></TR><TR><TD width=10 height=10 valign=bottom><IMG SRC=assets/bracket_bottom.gif></TD></TR></TABLE>';

	$page_footer_RET = DBGet(DBQuery("SELECT ID,LEFT_CELL,MIDDLE_CELL,RIGHT_CELL,TYPE FROM HEADER_ROWS WHERE TEMPLATE_ID='".$_REQUEST['template_id']."' AND TYPE='pagef'"),array('LEFT_CELL'=>'_makeCell','MIDDLE_CELL'=>'_makeCell','RIGHT_CELL'=>'_makeCell'));
	$page_footer_RET = $page_footer_RET[1];
	echo '<BR>';
	echo '<TABLE cellpadding=0 cellspacing=0><TR><TD rowspan=3><IMG SRC=assets/page_footer.gif></TD><TD width=10 height=10><IMG SRC=assets/bracket_top.gif></TD>';
	echo '<TD rowspan=3 width=100%>';
	DrawHeader('<TABLE style="display:inline;" width=100%><TR><TD>'.$page_footer_RET['LEFT_CELL'].'</TD><TD>'.$page_footer_RET['MIDDLE_CELL'].'</TD><TD>'.$page_footer_RET['RIGHT_CELL'].'</TD></TR></TABLE>');
	echo '</TD></TR>';
	echo '<TR><TD width=10 background=assets/bracket_middle.gif height=55> &nbsp;</TD></TR><TR><TD width=10 height=10 valign=bottom><IMG SRC=assets/bracket_bottom.gif></TD></TR></TABLE>';

	echo '<CENTER><INPUT type=submit value='._('Save').'></CENTER>';

	echo '<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />';
	echo "<DIV id=images_screen style=\"display:none;position:absolute;\" align=".ALIGN_LEFT."><IMG SRC=assets/arrow_up.gif><DIV class=BoxContents style='border-style:solid;border-width:1;border-color:#CCBBCC;' id=images_content></DIV></DIV>";
	echo '<DIV id=images_content_hidden style="visibility:hidden;"><TABLE cellpadding=6><TR><TD><INPUT type=file name=_name_><BR><font color=gray><small>'._('Title').'</small></font><INPUT type=text name=_titlename_ size=15><INPUT type=submit value='._('Upload').'></TD></TR></TABLE></DIV>';
	echo '<SPAN id=delete_image_hidden><INPUT type=hidden name=_name_ value=""></SPAN>';
	echo '</FORM>';
}

function _makeCell($value,$name,$type='')
{	global $THIS_RET,$field_options,$uploaded_assets_url;

	if($THIS_RET['ID'])
		$id = $THIS_RET['ID'];
	else
		$id = $type.'new';

	$text = substr($value,0,strrpos($value,'~'));
	$field_value = substr($value,strrpos($value,'~')+1);

	if(!$field_options)
	{
		$categories_RET = DBGet(DBQuery("SELECT ID,TITLE FROM STUDENT_FIELD_CATEGORIES ORDER BY SORT_ORDER,TITLE"),array(),array('ID'));
		$custom_RET = DBGet(DBQuery("SELECT TITLE,ID,TYPE,CATEGORY_ID FROM CUSTOM_FIELDS ORDER BY SORT_ORDER,TITLE"),array(),array('CATEGORY_ID','ID'));
		
		foreach($custom_RET as $category_id=>$fields)
		{
			if(AllowUse('Students/Student.php&category_id='.$category_id))
			{
				$field_options[$i++] = '-- '.$categories_RET[$category_id][1]['TITLE'].' --';
				if($category_id=='1')
					$field_options += array('FULL_NAME'=>_('Last, First M'),'FIRST_NAME'=>_('First'),'FIRST_INIT'=>_('First Initial'),'LAST_NAME'=>_('Last'),'MIDDLE_NAME'=>_('Middle'),'NAME_SUFFIX'=>_('Suffix'),'STUDENT_ID'=>_('Student ID'),'GRADE_ID'=>_('Grade'),'SCHOOL_ID'=>_('School'),'SYEAR'=>_('School Year'),'NEXT_SCHOOL'=>_('Rolling / Retention Options'),'CALENDAR_ID'=>_('Calendar'),'USERNAME'=>_('Username'),'PASSWORD'=>_('Password'));
					
				foreach($fields as $c_id=>$field)
					$field_options['CUSTOM_'.$c_id] = str_replace("'",'&rsquo;',$field[1]['TITLE']);
			}
		}
		if(AllowUse('Students/Student.php&category_id=3'))
			$field_options += array($i++=>_('-- Address --'),'ADDRESS'=>_('Address'),'CITY'=>_('City'),'STATE'=>_('State'),'CITY_STATE'=>_('City, State'),'ZIPCODE'=>_('Zip Code'),'ENTIRE_ADDRESS'=>_('Address City, State Zipcode'),'PHONE'=>_('Home Phone'),'MAIL_ADDRESS'=>_('Mailing Address'),'MAIL_CITY'=>_('Mailing City'),'MAIL_CITY_STATE'=>_('Mailing City, State'),'MAIL_STATE'=>_('Mailing State'),'MAIL_ZIPCODE'=>_('Mailing Zipcode'),'ENTIRE_MAILING_ADDRESS'=>_('Mailing Address City, State Zipcode'),'PARENTS'=>_('Contacts'));

		if(AllowUse('Grades/StudentRCGrades.php'))
		{
			$field_options += array($i++=>_('-- Grades --'),'SEM_GPA'=>_('Semester GPA'),'SEM_WEIGHTED_GPA'=>_('Semester Weighted GPA'),'QTR_GPA'=>_('Quarter GPA'),'QTR_WEIGHTED_GPA'=>_('Quarter Weighted GPA'),'SEM_CLASS_RANK'=>_('Semester Class Rank'),'QTR_CLASS_RANK'=>_('Quarter Class Rank'),'SEM_CREDITS'=>_('Semester Credits'),'QTR_CREDITS'=>_('Quarter Credits'));
		}

		$periods_RET = DBGet(DBQuery("SELECT TITLE,PERIOD_ID FROM SCHOOL_PERIODS WHERE SYEAR='".UserSyear()."' AND SCHOOL_ID='".UserSchool()."' ORDER BY SORT_ORDER"));
		$field_options[$i++] = _('-- Schedule --');
		foreach($periods_RET as $period)
			$field_options['PERIOD_'.$period['PERIOD_ID']] = $period['TITLE'].' '._('Teacher - Room');
	}
	if($THIS_RET['TYPE']=='pageh' || $THIS_RET['TYPE']=='pagef')
	{
		$old_field_options = $field_options;
		$field_options = array('$DATE'=>_('Date'),'$TIME'=>_('Time'),'$PAGE(1)'=>_('Page Number'),'$PAGE(1)/$PAGES(1)'=>_('Page/Total Pages')) + $field_options;
	}
	
	if(strpos($text,'<IMG SRC')===false)
	{
		if(!$text && !$field_value && ($THIS_RET['TYPE']!='pageh' && $THIS_RET['TYPE']!='pagef'))
			$return = '<span id=checkbox'.$id.$name.'><INPUT type=checkbox onclick="document.getElementById(\'span'.$id.$name.'\').style.display=\'inline\';document.getElementById(\'checkbox'.$id.$name.'\').style.display=\'none\';"></span><span style="display:none;" id=span'.$id.$name.'>';
		$return .= '<TABLE class=innerLO_field><TR><TD><b>'.TextInput($text,'values['.$id.']['.$name.'][text]','','size=7').'</font></TD>';
		$return .= '<TD><i>'.SelectInput($field_value,'values['.$id.']['.$name.'][field]','',$field_options,_('N/A'),'style="max-width:150;"').'</i></TD>';
		$return .= '</TR>';
		
		if($THIS_RET['TYPE']!='pageh' && $THIS_RET['TYPE']!='pagef')
		{	$return .= '<TR><TD colspan=2>';
			$return .= '<A HREF=# onclick="document.getElementById(\'images_screen\').style.display=\'block\';document.getElementById(\'images_content\').innerHTML=document.getElementById(\'images_content_hidden\').innerHTML.replace(\'_name_\',\'values['.$id.']['.$name.'][file]\').replace(\'_titlename_\',\'values['.$id.']['.$name.'][file_title]\');document.getElementById(\'images_screen\').style.left=getXPos(\'image'.$id.$name.'\');document.getElementById(\'images_screen\').style.top=(getYPos(\'image'.$id.$name.'\')+20);return false;"><img src="assets/image_icon.gif" id=image'.$id.$name.' border=0 height=10 align=center><small>'._('Add Image').'</small></A>';
			$return .= '</TD>';
			$return .= '</TR>';
		}
		else
			$field_options = $old_field_options;
		$return .= '</TABLE>';
		if(!$text && !$field_value && ($THIS_RET['TYPE']!='pageh' && $THIS_RET['TYPE']!='pagef'))
			$return .= '</span>';
	}
	else
	{
		$title = str_replace('_',' ',substr($text,(strlen($uploaded_assets_url)+11),-6));
		if(Preferences('MENU')=='Top')
			$submit = 'document.forms[1].submit();';
		else
			$submit = 'document.forms[0].submit();';			

		$return = '<A HREF=# onclick="document.getElementById(\'images_screen\').style.display=\'block\';document.getElementById(\'images_content\').innerHTML=document.getElementById(\'images_content_hidden\').innerHTML.replace(\'_name_\',\'values['.$id.']['.$name.'][file]\').replace(\'_titlename_\',\'values['.$id.']['.$name.'][file_title]\');document.getElementById(\'images_screen\').style.left=getXPos(\'image'.$id.$name.'\');document.getElementById(\'images_screen\').style.top=(getYPos(\'image'.$id.$name.'\')+20);return false;"><img src="assets/image_icon.gif" id=image'.$id.$name.' border=0 height=20 align=center></A><BR>'.$title.'<BR>';
		$return .= '<span id=delete_image_span></span><A HREF=# onclick="document.getElementById(\'delete_image_span\').innerHTML=document.getElementById(\'delete_image_hidden\').innerHTML.replace(\'_name_\',\'values['.$id.']['.$name.'][text]\');'.$submit.'return false;"><small>'._('Remove Image').'</small></A>';
	}
	return $return;
}

function _makeSortOrder($value,$name,$type='')
{	global $THIS_RET;
	
	if($THIS_RET['ID'])
		$id = $THIS_RET['ID'];
	else
		$id = $type.'new';
	
	$extra = 'size=5 maxlength=10';
	
	return TextInput($value,'values['.$id.']['.$name.']','',$extra);
}

function _makeStyle($value,$name,$type='')
{	global $THIS_RET;
	
	if($THIS_RET['ID'])
		$id = $THIS_RET['ID'];
	else
	{
		$id = $type.'new';
		$new = true;
	}

	$options = array('white'=>_('White'),'gray'=>_('Gray'),'blue'=>_('Blue'));
	
	return SelectInput($value,'values['.$id.']['.$name.']','',$options).'<BR>'._('With Border?').CheckboxInput($THIS_RET['BORDER'],'values['.$id.'][BORDER]','','',$new);
}
?>